package com.itheima.TCP.线程池;

import com.itheima.TCP.TCP接收协议.SocketThread;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10000);
        ThreadPoolExecutor tpe= new ThreadPoolExecutor(
                3,//核心线程数
                10,//最大线程数
                60,//临时线程的空闲时间
                TimeUnit.SECONDS,//临时线程的空闲时间单位
                new ArrayBlockingQueue<>(10),//任务过多时允许的排队线程数量
                Executors.defaultThreadFactory(),//线程的创建方法
                new ThreadPoolExecutor.AbortPolicy());

        while (true){
            Socket accept = ss.accept();
            //来一个客户端连接，创建一个线程去执行对应的上传任务
            tpe.submit(new SocketThread(accept));
        }
    }
}
